package ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.swing.*;


import controller.MobilePlanSellAndBillSystem;
import customexceptions.PlanAlreadyExistsException;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class SearchHistoricalsBillsUI extends javax.swing.JFrame {
	private JTextField jTextFieldHistoricFrom;
	private JButton jButtonAccept;
	private JLabel jLabelHistoricFrom;
	private JTextField jTextFieldHistoricTo;
	private JLabel jLabelHistoricTo;
	private JTextField jTextFieldPlanDiscount;
	private JLabel jLabelPlanDiscount;
	private MobilePlanSellAndBillSystem system;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				SearchHistoricalsBillsUI inst = new SearchHistoricalsBillsUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	public SearchHistoricalsBillsUI(){
		
	}
	public SearchHistoricalsBillsUI(MobilePlanSellAndBillSystem system) {
		super();
		initGUI();
		this.system = system;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jTextFieldHistoricFrom = new JTextField();
				getContentPane().add(jTextFieldHistoricFrom);
				jTextFieldHistoricFrom.setBounds(138, 47, 333, 28);
			}
			{
				jLabelHistoricFrom = new JLabel();
				getContentPane().add(jLabelHistoricFrom);
				jLabelHistoricFrom.setText("From (YYYY-MM-DD)");
				jLabelHistoricFrom.setBounds(12, 59, 126, 16);
			}
			{
				jTextFieldHistoricTo = new JTextField();
				getContentPane().add(jTextFieldHistoricTo);
				jTextFieldHistoricTo.setBounds(138, 87, 333, 28);
			}
			{
				jLabelHistoricTo = new JLabel();
				getContentPane().add(jLabelHistoricTo);
				jLabelHistoricTo.setText("To (YYYY-MM-DD)");
				jLabelHistoricTo.setBounds(12, 99, 119, 16);
			}		
				
			{
				jButtonAccept = new JButton();
				getContentPane().add(jButtonAccept);
				jButtonAccept.setText("Search");
				jButtonAccept.setBounds(206, 205, 84, 23);

				jButtonAccept.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent evt) 
					{
							try {
									
								SimpleDateFormat dateFormat;
								dateFormat = new SimpleDateFormat("yyyy-MM-dd");
								java.util.Date parsedDate; 
								java.sql.Timestamp timestampFrom;
								java.sql.Timestamp timestampTo;
								parsedDate = dateFormat.parse(jTextFieldHistoricFrom.getText());
								timestampFrom = new java.sql.Timestamp(parsedDate.getTime());
								parsedDate = dateFormat.parse(jTextFieldHistoricTo.getText());
								timestampTo= new java.sql.Timestamp(parsedDate.getTime());
								HistoricBillView  historicBillView = new HistoricBillView();
								historicBillView.historicBillViewPerPeriod(
										system.getHistoricPerPeriod(timestampFrom,timestampTo));
								historicBillView.setVisible(true);
							} catch (ParseException e) {
								ErrorReportView errorReportView = new ErrorReportView(e.getMessage());
								errorReportView.setVisible(true);
							}

							jTextFieldHistoricFrom.setText("");
							jTextFieldHistoricTo.setText("");
					}
				});
				
			}
			pack();
			this.setSize(506, 294);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
